<?php
if (!function_exists("GetSQLValueString")) {
	function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
	{
	  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
	  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

	  switch ($theType) {
		case "text":
		  $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
		  break;    
		case "long":
		case "int":
		  $theValue = ($theValue != "") ? intval($theValue) : "NULL";
		  break;
		case "double":
		  $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
		  break;
		case "date":
		  $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
		  break;
		case "defined":
		  $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
		  break;
	  }
	  return $theValue;
	}
}

function getKategori($kat,$g=0) {
	if($g) { 
		$query_get_kat_id = sprintf("SELECT id_kategori FROM p_kategori WHERE id_produkt = %s LIMIT 1", GetSQLValueString($kat, "int")); 
		$get_kat_id = mysql_query($query_get_kat_id) or die(mysql_error());
		$row_get_kat_id = mysql_fetch_assoc($get_kat_id);
		$kat = $row_get_kat_id['id_kategori'];
	}
	$query_get_kat = sprintf("SELECT text, o_kat FROM kategori WHERE id = %s LIMIT 1", GetSQLValueString($kat, "int"));
	$get_kat = mysql_query($query_get_kat) or die(mysql_error());
	$row_get_kat = mysql_fetch_assoc($get_kat);
	return array($row_get_kat['text'],$row_get_kat['o_kat']);
}

function makePaginA($url,$text,$class,$title,$Link=1) {
	if($Link) {	
		return "<a href=\"".$url."\" class=\"".$class."\" title=\"".$title."\">".$text."</a>";
	}
	return $text;
}
function makePagin($kat){
	$pageNum=0;
	$pNrPages = 1;
	$pPerPage		= 10000;
	$pStart			= 0;
	$pEnd			= $pPerPage + $pStart;
	$pBtnHtml = '<span id="paginText" class="PaginBtnNmbr">sidan '.($pageNum+1).' av '.$pNrPages.'<a href="javascript:showAll()"> (visa alla)</a></span>';
	$pBtnHtml = makePaginA('javascript:goToPrevPage();','&nbsp;','PaginBtnLeft','G&aring; till f&ouml;reg&aring;ende sida med '.$kat).$pBtnHtml;
	$pBtnHtml = $pBtnHtml.makePaginA('javascript:goToNextPage();','&nbsp;','PaginBtnRight','G&aring; till n&auml;sta sida med '.$kat);
	$pBtnHtml = '<table><tr><td>'.$pBtnHtml.'</td></tr></table>';
	return array($pStart,$pPerPage,$pBtnHtml);
}

function makePaginOLD($sql,$pPerPage,$kat){
	$pageNum=0;
	/*if (isset($_GET['pageNum']) && GetSQLValueString($_GET['pageNum'],'int') > 0) {
			$pageNum = GetSQLValueString($_GET['pageNum'],'int');
	}
	foreach ($_GET as $a => $b) {
		if ($a !== "pageNum") {
			$currentQuery = $currentQuery.$a."=".$b."&amp;";
		}
	}	
	*/
	$pPerPage		= $pPerPage;
	$pStart			= $pPerPage * $pageNum;
	$pEnd			= $pPerPage + $pStart;
	$pQuery			= $sql;
	$pQueryGetData	= sprintf("%s LIMIT %d, %d", $pQuery, $pStart, $pPerPage);
	$currentPage	= $_SERVER["PHP_SELF"];

		mysql_select_db($database_dia_t001);
		$pGetNrRows = mysql_query($pQuery);
		$pNrRows = mysql_num_rows($pGetNrRows);
	
	$pNrPages = ceil($pNrRows / $pPerPage);

	$pBtnHtml = '<span id="paginText" class="PaginBtnNmbr">sidan '.($pageNum+1).' av '.$pNrPages.'<a href="javascript:showAll()"> (visa alla)</a></span>';
	
	/*if($pageNum > 0) {
		$pBtnHtml = makePaginA($currentPage,$currentQuery,($pageNum-1),'&nbsp;','PaginBtnLeft','G&aring; till f&ouml;reg&aring;ende sida med '.$kat).$pBtnHtml;
	}else {
		$pBtnHtml = makePaginA($currentPage,$currentQuery,($pageNum),'&nbsp;','PaginBtnLeft','').$pBtnHtml;
	}*/
	$pBtnHtml = makePaginA('javascript:goToPrevPage();','&nbsp;','PaginBtnLeft','G&aring; till f&ouml;reg&aring;ende sida med '.$kat).$pBtnHtml;
	
	/*if($pageNum < $pNrPages-1) {
		$pBtnHtml = $pBtnHtml.makePaginA($currentPage,$currentQuery,($pageNum+1),'&nbsp;','PaginBtnRight','G&aring; till n&auml;sta sida med '.$kat);
	}else {
		$pBtnHtml = $pBtnHtml.makePaginA($currentPage,$currentQuery,($pageNum),'&nbsp;','PaginBtnRight','');
	}*/
	$pBtnHtml = $pBtnHtml.makePaginA('javascript:goToNextPage();','&nbsp;','PaginBtnRight','G&aring; till n&auml;sta sida med '.$kat);
	
	
	$pBtnHtml = '<table><tr><td>'.$pBtnHtml.'</td></tr></table>';
	return array($pStart,$pPerPage,$pBtnHtml);
}
?>